All Questions
Tagged with functional-programmingjava
49 questions
4votes
6answers
422views
Search values by priority in a Stream
I have a simple list of results, and I need to return only one value depending on content, for example: ...
3votes
1answer
101views
In Java, replace for loop with condition with lambdas [closed]
I want to replace a for loop with a break/return condition inside with a lambda. I think I have a good replacement, but I want ...
5votes
2answers
161views
Print the three most occurring chars in Java using streams
The three characters that occurs most in a given string should be printed by using streams/lambdas (functional programming). The order of characters that occur equally often should be preserved. My ...
3votes
1answer
104views
Sequentially find the indexes of an element into a collection
Util class to find into a collection the indexes of a given element with multiple occurrences from the first index or relative to a given index. ...
2votes
1answer
128views
Stream Partitioner
Discussion I've been trying to increase my knowledge of Java Streams and for practice, I devised up the requirement of partitioning a Stream of values into a ...
2votes
2answers
467views
A Union Data Type
Introduction I'm trying to get familiar with functional programming by implementing some functional concepts. One of these concepts that I've attempted to implement below is a ...
3votes
2answers
437views
Streaming substrings of a string
Given a (long) string src, generate substrings (up to) len characters long on demand by iterating over ...
3votes
2answers
179views
Compute variance via functional programming
So I'm supposed to calculate variance based on this forumula through functional programming: $$\sigma^2 = \frac{\sum\limits_{i=0}^{n-1} (X -\mu)^2}{n-1}$$ This is the code that works: ...
3votes
1answer
654views
Updates or creates an entity based on if a value is present in an Optional
I need to get car info from a 3rd party web service and persist the data in my application DB. If my DB already has the car, I only update property values that may have changed. Otherwise, I create ...
3votes
2answers
4kviews
Hackerrank problem: Climbing the Leaderboard (Java)
I am solving the following Hackerrank problem: Climbing the Leaderboard. The problem statement: Alice is playing an arcade game and wants to climb to the top of the leaderboard and wants to track her ...
3votes
2answers
215views
Creating a new list using a stream
I have a StudentSchedule class that contains schedules of a student, the student may switch between rooms over time. There's no overlap with the date ranges so if a student stops at 2020-01-01 the ...
3votes
2answers
162views
Leap year check in Java (functional style)
I have done the leap year check on https://exercism.io already in a lot of languages. Today I came back to the exercise in Java and was playing around with some maybe more funny ways to do the check. ...
0votes
1answer
102views
Pure methods for updating java objects
I've been reading about pure methods and immutability in Java. I have a current application and want to convert all the methods to pure methods. My app takes payment from users. I first create a ...
1vote
1answer
310views
FizzBuzz with Lambda Expressions in Java
I wanted to create a FizzBuzz in Java that is supposed to be open for extension. So the initial problem is the good old, if divisible by 3 print fizz, if divisible by 5 print buzz, if divisible by ...
1vote
3answers
113views
Picking from a list of individuals based on their fitness values
I have this method that takes a list of my individuals (class has public field fitnessValue). I sum all fitnessValue and then ...